package com.gameplatform.servlet;

import com.gameplatform.service.AnalyticsService;
import com.gameplatform.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;


//数据分析的Servlet
public class AnalyticsServlet extends HttpServlet {
    private AnalyticsService analyticsService = new AnalyticsService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String pathInfo = request.getPathInfo();

        if (pathInfo != null && pathInfo.equals("/dashboard")) {
            Map<String, Object> data = analyticsService.getDashboardData();
            ResponseUtil.writeResponse(response, 200, "success", data);
        } else {
            ResponseUtil.writeResponse(response, 404, "Endpoint not found", null);
        }
    }
}